<!DOCTYPE html>
<html>
<head>
<div th:include="base-libs :: base-libs" />
<title>床位设置</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">

<style>
	.laydate-icon{
		width:87% !important;
		padding-left: 5px;
		line-height: 28px;
		background-color: #fff;
		height: 28px;
		border: 1px solid #B6B6B6;
		border-radius: 5px;
	}
	.spanBtn{
		font-weight: bold;
    	color: blue;
    	cursor:pointer;
	}
</style>

<script th:inline="javascript">
	/**读取request中的初始化数据*/
	var requestData = [[${requestData}]];
</script>
<script>
	$(function(){
		$(this).registerManagerPage();
		initView();
		initData();
    })
    
    function initData(){
        //根据权限，隐藏不能使用的查询条件
        if(!requestData["isManager"]){
            var value = {PTJGID: parent.userInfo.PTJGID,YLJGMC: parent.userInfo.YLJGMC};
            $("#combogridYljg").combogrid("setValue", value);
            initKsxx(value)
            $(".hidden").hide();
        }

		$("#btnQuery").trigger("click");
	}
    	
    function initView() {
        /** 医疗机构combogrid */
        var readonly = !requestData["isManager"];
    	$("#combogridYljg").combogrid({
            height: 30
            ,width: 300
            ,panelWidth: 500
            ,singleSelect: true
            ,pagination: true
            ,idField: 'PTJGID'
            ,textField: 'YLJGMC'
            ,mode: "remote"
            ,readonly: readonly
            ,hasDownArrow: !readonly
            ,url: "/console/yljgxx/queryPageSummary.service"
            ,delay: 1000
            ,reversed: false
            ,fitColumns: true
            ,columns:[[
                {field:'YLJGMC',title:'机构名称',width:240},
                {field:'XZQHMC',title:'行政区划',width:80},
                {field:'WSJGLBMC',title:'机构类别',width:90},
                {field:'YYDJMC',title:'机构等级',width:80}
            ]]
            ,onBeforeLoad: function(queryParams) {
                var url = $(this).datagrid("options")["url"];
				/*URL不等空时再发送请求*/
                if (url) {
                    queryParams["pageSize"] = queryParams["rows"];
                    queryParams["pageNumber"] = queryParams["page"];
                    queryParams["YLJGMC"] = queryParams["q"];
                    return true;
                }else{
                    return false;
                }
            },
            onClickRow : function(rowIndex, rowData){
    			initKsxx(rowData);
            },
            onLoadSuccess : function(data){

			}
        });
		
		//点击input展开combogrid
		$(".validatebox-text").click(function(){
			$('.combo-arrow').trigger('click');
		})
    	
		$("#cwszTb").datagrid({
				idField : "CWSZBH",
				striped : true,
				clickToSelect: true,
				fitColumns: true,
				fit:true,
				scrollbarSize:15,
				singleSelect: true,
				columns : [[
// 						{field : "xz",checkbox:true},
						{field : "YLJGMC",title : "医疗机构名称",width:80, align:'center'},
						{field : "YJKSMC",title : "科室名称",width:80, align:'center'},
						{field : "BQMC",title : "病区名称",width:80, align:'center'},
						{field : "SFQYCW",title : "是否启用床位预约",width:60, align:'center', formatter:function(value){
							var obj = {'0':'否','1':'是'};
							return obj[value] || value;
						}},
						{field : "KYYCWS",title : "可预约床位占比(%)",width:60, align:'center'},
						{field : "SFXYSH",title : "是否需审核",width:60, align:'center', formatter:function(value){
							var obj = {'0':'否','1':'是'};
							return obj[value] || value;
						}},
// 						{field : "ZT",title : "状态",width:80, align:'center', formatter:function(value){
// 							var obj = {'1':'正常','2':'待审核','3':'审核不通过',};
// 							return obj[value] || value;
// 						}},
						{field : "CZ",title : "操作",width:60, align:'center', formatter:function(value,row){
							var rowCopy = JSON.stringify(row).replace(/"/g, '&quot;');
							var s = '<span class="spanBtn" onclick="toAddView('+ rowCopy +')">修改</span>';
							var x = '<span class="spanBtn" onclick="deleteCwsz('+ rowCopy +')">删除</span>';
							var result;
							if(row.ZT == 3 || row.SFQYCW == 0){ // 审核不通过||未启用
								return s +"&nbsp;&nbsp" + x;
							}else{
								return x;
							}
						}}
				]],
				pagination : true,
				pageList: [10, 20, 50, 100, 200],
				method : "post",
				onBeforeLoad : function(params) {
					var YYDJMC = $("#YYDJMC>option:selected").text();
					if(YYDJMC != '请选择'){
						params.YYDJMC = YYDJMC;
					}
					params.PTJGID = $("#combogridYljg").combobox("getValue");
					getContainerDataByClassName('conditionBox','condition',params);//查询条件
				},
				onLoadSuccess: function(data){
// 					alert(JSON.stringify(data))
 				},
		});

	}
    
    /** 初始化一级科室下拉框 */
	function initKsxx(params2){
		var params = $.extend({},params2);//处理乱码
        $.QuickRemote.AjaxJson("/console/ksxx/", function(result){
            $("#YJKSDM").createOptions(result,{textField : "KSMC" , valueField : "KSDM"});
        }, params);
	}

    	
   	/** 查询  */
   	function btnQueryHandler(){
   	    $("#cwszTb").datagrid({"url": "queryPage.service"});
   	}
   	
   	/** 跳转到新增页面  */
   	function toAddView(row){
   		StoreCache.setCache('cwszData',row);
   		$.QuickUrlUtils.redirectUrl("manager.html");
   	}
   	
   	/** 删除床位设置  */
   	function deleteCwsz(row){
   		$.QuickAlert.alertConfirm({
			content : "删除后不可恢复，是否继续？",
			callback : function() {
				$.QuickRemote.AjaxJson("delete", deleteHandler, row);
			}
		})
   	}
   	
   	/** 删除回调 */
	function deleteHandler(result){
		if(result.state){
			$.QuickAlert.alertNormal(result.info, {callback: function(){
				$("#btnQuery").trigger("click");
			}});
		}else{
			$.QuickAlert.alertFail({content: result.info});
		}
	}
</script>

</head>

<body>
	<div class="easyui-layout" fit="true" border="false" id="mylayout">
		<div region="north" id="north" style="overflow:hidden;padding:15px 0px;background:#f9f9f9" border="false">
			<form action="downloadWdqyhz.service" method="post" enctype="multipart/form-data" id="downloadForm" >
				<table class="form-table" id="conditionBox">
					<tr class="hidden">
						<td class="td-text">医院等级：</td>
						<td class="td-content">
							<select id="YYDJMC" class="condition" cacheTable="TB_ZY_YYDJ" style="width:91%">
							</select>
						</td>
						<td class="td-text">医疗机构名称：</td>
						<td class="td-content">
							<input id="combogridYljg"/>
						</td>
						<td class="td-text"></td>
					</tr>
					<tr class="activeQuery">
						<td class="td-text">科室名称：</td>
						<td class="td-content">
							 <select id="YJKSDM" name="YJKSDM" class="form-control condition" style="width:91%">
								<option value="">请选择</option>
							</select>
						</td>
						<td class="td-text">病区名称：</td>
						<td class="td-content">
							<input name="BQMC" class="form-control condition" style="width:82%"/>
						</td>
						<td class="td-text" style="width:170px;text-align:center">
							<button id="btnQuery" class="btn btn-info" type="button" onclick="btnQueryHandler()">查询</button>
							<button type="button" onclick="toAddView()">新增</button>
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div region="center" border="false">
			<table id="cwszTb" border="false"></table>
		</div>
	</div>
	
</body>
</html>
